<?php    
    define( 'VERSION', 1.0 );
    include 'config.php';
    
    $twip = new twip($options);
    
    
function sent_message(){
	include 'Service.php';
	include 'douban/Douban.php';
	include 'init.php';
	global $services;
	$pattern = getPattern();
   	$content = $_POST['status'];
    if( !empty( $pattern ) ){
    	if(preg_match ( $pattern, $content ) )
    	return;
    }
    if ( empty ( $pattern ) )
    return;
    	
    		foreach ( $services as $k => $v ) {
    			if (trim ( $k ) == '') {
    				continue;
    			}
	
			if (trim ( $v ['username'] ) == '' || trim ( $v ['password'] ) == '') {
				continue;
			}
	
			$service = ucfirst ( $k );
			$service = new $service ( );
			$service->setUsername ( $v ['username'] );
			$service->setPassword ( $v ['password'] );
			$service->setContent ( $content );
			$service->update ();
	}
}



function getPattern() {
		global $twitterSyncLevel;
		switch ($twitterSyncLevel) {
			//过滤回复别人的tweet
			case 1 :
				return '/^@.*/m';
				break;
			
			//过滤RT别人的推	
			case 2 :
				return '/^RT\s@.*/m';
				break;
			
			//只同步自己的tweet,推中不包含RT,@字样	
			case 3 :
				return '/RT\s|@/';
				break;
			
			default :
				return NULL;
				break;
		}
	}


function record($msg){
    file_put_contents("log.txt",$msg,FILE_APPEND);
}
	


?>